const OSS = require('ali-oss');

  const client = new OSS({
    accessKeyId: "LTAI5tGEu9MsMV17czps9Een",
    accessKeySecret: 'tomC91ciIT4k2WeRICQXzXrSYVmBBz',
    region: "oss-cn-beijing", // oss地域，如oss-cn-hangzhou
    bucket: 'hanrruifeng'    // 要上传的bucket名称
  });

export async function uploadFile(file) {

  const fileName = file.name;
  // 生成唯一文件名，可根据需求自定义
  const uniqueFileName = `${Date.now()}-${fileName}`;
  // 调用OSS SDK上传文件
  return new Promise((resolve, reject) => {
    client.put(uniqueFileName, file).then(result => {
      console.log('文件上传成功:', result);
      const url = result.url
      resolve(url);
    }).catch(err => {
      console.error('文件上传失败:', err);
      reject(err);
    });
  })

}
